<%@ page import="BookManage.dao.BookManageDao" %>
<%@ page import="BookManage.dao.Impl.BookManageDaoImpl" %>
<%@ page import="BookManage.Servlet.BookManageServlet" %>
<%@ page import="BookManage.Servlet.Impl.BookManageImplServlet" %>
<%@ page import="BookManage.BookManage" %>
<%@ page import="java.util.List" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Lenovo
  Date: 2021/9/21
  Time: 14:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<%
    BookManageDao bookManageDao=new BookManageDaoImpl();
    int tot=bookManageDao.getTotalCount();

    Integer Size=null;
    if(tot%5==0){
        Size=(tot/5);
    }else if(tot%5!=0){
        Size=(tot/5)+1;
    }
    System.out.println(Size);

    String pages=request.getParameter("BookNo");
    Integer pageNo=null;
    if(null==pages){
        pageNo=1;
    }else{
        pageNo=Integer.parseInt(request.getParameter("BookNo"));
    }
    BookManageServlet bookManageServlet=new BookManageImplServlet();
    List<BookManage> lists=bookManageServlet.list(pageNo,5);
    request.setAttribute("Size",Size);
    request.setAttribute("pageNo",pageNo);
    request.setAttribute("lists",lists);
%>
<body>
<table border="1" align="center">
    <tr>
        <th>图书名称</th>
        <th>图书作者</th>
        <th>购买时间</th>
        <th>图书分类</th>
    </tr>
    <c:forEach items="${requestScope.lists}" var="l">
        <tr>
            <td>${l.name}</td>
            <td>${l.author}</td>
            <td>${l.date}</td>
            <td>${l.type}</td>
            <td><a href="/untitled1_war_exploded/dd?id=${l.id}">删除</a></td>
            <td><a href="http://localhost:8080/untitled1_war_exploded/BookManage/xg.jsp?id=${l.id}&name=${l.name}&author=${l.author}&date=${l.date}&type=${l.type}">修改</a></td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="4">
            <a href="/untitled1_war_exploded/cx?BookNo=1">首页</a>
            <c:if test="${pageNo>1}">
                <a href="/untitled1_war_exploded/cx?BookNo=${pageNo-1}">上一页</a>
            </c:if>
            <c:if test="${pageNo<Size}">
                <a href="/untitled1_war_exploded/cx?BookNo=${pageNo+1}">下一页</a>
            </c:if>
            <a href="/untitled1_war_exploded/cx?BookNo=${Size}">尾页</a>
        </td>
    </tr>
</table>
<a href="http://localhost:8080/untitled1_war_exploded/BookManage/xz.jsp">新增图书信息</a>
</body>
</html>
